package com.liliudong.template.api.admin.config;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.liliudong.template.common.security.impl.StpInterfaceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SaTokenConfigure
 *
 * @author ldli5
 * @classname SaTokenConfigure
 * @date 2024/6/18-8:59
 */
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new SaInterceptor(handler -> StpUtil.checkLogin()))
				.addPathPatterns("/**")
				.excludePathPatterns("/v1/sys/user/login");
	}

	@Bean
	public StpInterface stpInterface() {
		return new StpInterfaceImpl();
	}
}

